<template>
	<view class="text-center" style="margin-top: 30px;">
		<image style="width: 64px;height: 64px;" src="/static/login.png"></image>
		<view class="margin">申请获取您的昵称、头像<view class="text-grey">为您提供更好的服务</view></view>
		<view class="padding">
			<button @getuserinfo="wxGetUserInfo" open-type="getUserInfo" size="mini" style="margin-top: 30px;background-color: #1C232B;color: #FFFFFF;width: 50% !important;">微信登录</button>
		</view>
	</view>
</template>

<script>
	export default {
		methods: {
			wxGetUserInfo: function(res) {
				var that = this;
				if (!res.detail.iv) {
					uni.showToast({
						title: "取消了授权,登录失败",
						icon: "none"
					});
					return false;
				}
				//console.log('-------用户授权，并获取用户基本信息和加密数据------')
				//console.log(res.detail);
				var param = {
					encryptedData: res.detail.encryptedData,
					iv: res.detail.iv,
					rawData: res.detail.rawData,
					signature: res.detail.signature,
					appid: uni.getAccountInfoSync().miniProgram.appId
				}
				this.$get('tencent/microapp/setuserinfo', param, 'post', true).then((res) => {
					if (res.data) {
						uni.setStorage({
							key: 'userinfo',
							data: res.data,
							success() {
								uni.navigateBack({
									delta: 1
								})
							}
						})

					}
				});

			},
		}
	}
</script>

<style>
</style>
